CC=g++
CFLAGS=-c -Wall -g -std=c++0x
LDFLAGS=-lmpg123 -lsndfile -pthread
#LDFLAGS=-lmpg123 -lpthread
INCLUDE_FLAGS=-I/usr/local/include

EXE_SOURCES_CPP= NmpsRadioStreamer.cpp streamerDemo.cpp
EXE_OBJECTS=$(EXE_SOURCES_CPP:.cpp=.o)
UTIL_SOURCES_CPP=  usageHelper.cpp AppLogger.cpp HttpHelper.cpp ParsingUtils.cpp \
		TranscoderUtils.cpp PcmPlayoutBuffer.cpp RtpStreamer.cpp PCM_Data_Block.cpp RtpHeader.cpp BitUtils.cpp \
		SipMessage.cpp SipDialog.cpp SipHeader.cpp SipResponse.cpp SipRequest.cpp SipServer.cpp RadioStreamer.cpp \
		RadioChannel.cpp RadioStreamerStats.cpp RadioStation.cpp
UTIL_OBJECTS= $(UTIL_SOURCES_CPP:.cpp=.o) 
OBJECTS=$(UTIL_OBJECTS) $(EXE_OBJECTS) 
EXECUTABLE=NmpsRadioStreamer streamerDemo

SOURCES= NmpsRadioStreamer.cpp usageHelper.cpp AppLogger.cpp HttpHelper.cpp ParsingUtils.cpp \
		TranscoderUtils.cpp PcmPlayoutBuffer.cpp RtpStreamer.cpp PCM_Data_Block.cpp RtpHeader.cpp BitUtils.cpp \
		SipMessage.cpp SipDialog.cpp SipHeader.cpp SipResponse.cpp SipRequest.cpp SipServer.cpp RadioStreamer.cpp \
		RadioChannel.cpp RadioStreamerStats.cpp RadioStation.cpp
		
all: $(SOURCES) $(EXECUTABLE) UnitTest
	
$(EXECUTABLE): $(OBJECTS)
	$(CC) $(LDFLAGS) $(UTIL_OBJECTS)  $@.o -o $@
	
.cpp.o:
	$(CC) $(CFLAGS) $< -o $@ ${INCLUDE_FLAGS}

.PHONY: clean run UnitTest

#mpg123_to_wav: mpg123_to_wav.c
#	$(CC) -g mpg123_to_wav.c -o  $@ -lsndfile -lmpg123

#timerTest: TimerTest.c
#	$(CC) $< -o $@ ${INCLUDE_FLAGS}

readWavFile: readWavFile.cpp
	$(CC) $< -o $@ ${INCLUDE_FLAGS}
	
#this target will compile and run the unit tests
UnitTest: UnitTest.cpp 
	${CC} $(LDFLAGS) UnitTest.cpp $(UTIL_OBJECTS) -o UnitTest
	./UnitTest
	
run: all
	@echo 'Executing the target: ${EXECUTABLE}'
	./NmpsRadioStreamer -u http://www.shoutcast.com/radio/News -c192.168.126.132:54321,130.233.84.254:12345
clean:
	rm -f *.o *.log ${EXECUTABLE} core UnitTest *.wav
